<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of LanguagesController
 *
 * @author zxcms
 */
class Cms_LanguagesController extends H_Controller_Cms_Action {   
    public function indexAction(){
        $lg = $this->_getParam('lg', H_G::AD_DEFAULT_LANG);
        $translate = Zend_Registry::get(H_G::T_AD_TRANSLATE);
        $translateSource = $translate->getTranslateSource($lg);        
        
        $appPath = APPLICATION_PATH;
        
        $dirScan = array(
            $appPath."/modules/".$this->_request->getModuleName(),
            $appPath."/templates/".$this->_request->getModuleName(),
        );
        
        $basePath = BASE_PATH;
        $loader = Zend_Loader_Autoloader::getInstance();
        $autoLoader = $loader->getRegisteredNamespaces();
        foreach ($autoLoader as $loaderItem){
            if ($loaderItem == 'Zend_' || $loaderItem == 'ZendX_') continue;
            array_push($dirScan,$basePath."/library/". substr($loaderItem, 0,  strlen($loaderItem)-1) );
        }
        
        $renderSource = new H_Translate_RenderArraySource($lg, $appPath."/modules/".$this->_request->getModuleName()."/languages", $dirScan);
        $allKeyword = $renderSource->scankeyword();
     
        foreach ($allKeyword as $key=>$item){
            foreach ($translateSource as $keys => $items){
                if ($key == $keys){
                    $allKeyword[$key] = $items;
                }
            }
        }

        if ($this->_request->isPost()){                        
            $renderSource->excesave($this->_getParam('translate'));
            $this->_redirect("/cms/languages/".$this->_request->getActionName()."/lg/$lg");
        }
        $this->view->lg = $lg;
        $this->view->allKeyword = $allKeyword;
    }
    public function siteAction(){       
        $lg = $this->_getParam('lg', H_G::$DEFAULT_LANG);
        $translate = Zend_Registry::get(H_G::T_TRANSLATE);
        $translateSource = $translate->getTranslateSource($lg);  
        $appPath = APPLICATION_PATH;
        $dirScan = array();
        foreach (H_G::$ALL_SITE_MODULE as $moduleName){
            array_push($dirScan, $appPath."/modules/".$moduleName);
            array_push($dirScan, $appPath."/templates/".$moduleName);
        }

        $renderSource = new H_Translate_RenderArraySource($lg, $appPath."/languages", $dirScan);
        
        $allKeyword = $renderSource->scankeyword();

        foreach ($allKeyword as $key=>$item){
            foreach ($translateSource as $keys => $items){
                if ($key == $keys){
                    $allKeyword[$key] = $items;
                }
            }
        }

        if ($this->_request->isPost()){
            $renderSource->excesave($this->_getParam('translate'));
            $this->_redirect("/cms/languages/".$this->_request->getActionName()."/lg/$lg");
        }
        $this->view->lg = $lg;
        $this->view->allKeyword = $allKeyword;
    }
    public function  postDispatch() {
        parent::postDispatch();
        $this->view->actionName = $this->_request->getActionName();
    }
  
}
?>
